//
// Created by Administrator on 2021/10/25.
//

#ifndef MRENDER_IDRAWUIABLE_H
#define MRENDER_IDRAWUIABLE_H

/**
 * 支持UI界面接口
 */
 static unsigned int showMaxArraySize = 100;
class IDrawUIable {
public:
    /**
     * 绘制UI界面
     */
    virtual void drawUI() = 0;

    /**
     * 显示tips
     * @param desc
     */
    static void HelpMarker(const char* desc) {
        ImGui::TextDisabled("(?)");
        if (ImGui::IsItemHovered())
        {
            ImGui::BeginTooltip();
            ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
            ImGui::TextUnformatted(desc);
            ImGui::PopTextWrapPos();
            ImGui::EndTooltip();
        }
    }

    /**
     * 展示数组，多余的用 ...省略
     * @param data 数组
     * @param numComPonent 数据分量个数
     */
     static void vectorToImGuiText(const std::vector<float> &data, int numComPonent) {

        unsigned len = data.size() > showMaxArraySize ? showMaxArraySize : data.size();

        String sdata;
        for(int i = 0; i < len; i++){
            bool nextFlag = (i+1) % numComPonent == 0;
            sdata += String::toString(data[i]);
            if(nextFlag){
                sdata += "\n";
            }else {
                sdata += ",";
            }
        }

        if(data.size() > 3){
            HelpMarker(sdata.c_str());
            ImGui::SameLine();
            ImGui::Text("Len: %d", data.size());
        }else{
            ImGui::Text("%s", sdata.c_str());
        }
    }

    /**
     * 展示数组，多余的用 ...省略
     * @param data 数组
     * @param numComPonent 数据分量个数
     */
    static void vectorToImGuiText(const std::vector<int> &data, int numComPonent) {
        unsigned len = data.size() > showMaxArraySize ? showMaxArraySize : data.size();

        String sdata;
        for(int i = 0; i < len; i++){
            bool nextFlag = (i+1) % numComPonent == 0;
            sdata += String::toString(data[i]);
            if(nextFlag){
                sdata += "\n";
            }else {
                sdata += ",";
            }
        }

        if(data.size() > 3){
            HelpMarker(sdata.c_str());
            ImGui::SameLine();
            ImGui::Text("Len: %d", data.size());
        }else{
            ImGui::Text("%s", sdata.c_str());
        }
    }
};

#endif //MRENDER_IDRAWUIABLE_H
